import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pluginLib from './plugins/plugin-lib'
import { visualizer } from 'rollup-plugin-visualizer'

// https://vitejs.dev/config/
export default defineConfig({
  base: '',
  publicDir: false,
  resolve: {
    alias: {
      '~': path.resolve(__dirname, './'),
      '@': path.resolve(__dirname, 'src')
    }
  },
  build: {
    outDir: 'lib',
    lib: {
      entry: path.resolve(__dirname, 'install.js'),
      formats: ['es'],
      fileName: 'index'
    },
    /** 排除无需打包进去的依赖库 */
    rollupOptions: {
      external: [
        'vue',
        'element-plus',
        'vant',
        'axios',
        'lodash',
        'moment',
        'sortablejs',
        '@element-plus/icons-vue',
        '@marshallswain/vuedraggable',
        'ace-builds',
        'ace-builds/src-min-noconflict/mode-javascript',
        'ace-builds/src-min-noconflict/mode-json5',
        'ace-builds/src-min-noconflict/mode-text',
        'ace-builds/src-min-noconflict/theme-chrome',
        'ace-builds/src-min-noconflict/theme-eclipse',
        'ace-builds/src-min-noconflict/ext-language_tools'
      ]
      // output: {
      //   entryFileNames: 'index.js'
      // }
    },
    minify: false
  },
  plugins: [
    pluginLib(),
    vue(),
    // 可视化Bundle
    visualizer({
      emitFile: true,
      filename: 'stats.html'
    })
  ],
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler',
        silenceDeprecations: ['legacy-js-api'] // 重点：解决sass警告问题
      }
    }
  }
})
